<!-- 内容标题（页面标题） -->
<section class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1>个人中心</h1>
			</div>
			<div class="col-sm-6">
				<ol class="breadcrumb float-sm-right">
					<li class="breadcrumb-item"><a href="javascript:void(0)" onclick="loadSubPage('login')">用户</a></li>
					<li class="breadcrumb-item active">登录</li>
				</ol>
			</div>
		</div>
	</div><!-- /.container-fluid -->
</section>
<!-- 主体内容 -->
<div class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12 register-page">
				<div class="login-box">
					<!-- /.login-logo -->
					<div class="card card-info">
						<div class="card-header text-center">
							<a href="index.html" class="h1"><b>bby</b>云U盘</a>
						</div>
						<div class="card-body">
							<p class="login-box-msg">帐户登录</p>
							<form action="javascript:void(0)" id="loginForm" method="post" name="loginForm" onsubmit="doLogin(this)">
								<div class="input-group mb-3">
									<input type="email" name="email" class="form-control" placeholder="邮箱">
									<div class="input-group-append">
										<div class="input-group-text">
											<span class="fas fa-envelope"></span>
										</div>
									</div>
								</div>
								<div class="input-group mb-3">
									<input type="password"name="password"  class="form-control" placeholder="密码">
									<div class="input-group-append">
										<div class="input-group-text">
											<span class="fas fa-lock"></span>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col">
										<div class="icheck-primary">
											<input type="checkbox" id="remember">
											<label for="remember" class="font-size-sm" id="rem">
												记住我的登录状态
											</label>
										</div>
									</div>
									<div class="col-auto"><a href="forgot-password.html">忘记密码</a></div>
								</div>
								<div class="checkmsg text-red"  id="checkmsg"></div>
								<div class="row">
									<!-- /.col -->
									<div class="col">
										<button type="submit" class="btn btn-primary btn-block" id="login">登录</button>
									</div>
									<!-- /.col -->
								</div>
							</form>

							<p class="mb-1">

							</p>
							<p class="mb-0">
								<a href="javascript:void(0)" class="text-center"
									onclick="loadSubPage('register')">注册新用户</a>
							</p>
						</div>
						<!-- /.card-body -->
					</div>
					<!-- /.card -->
				</div>
				<!-- /.col-md-6 -->
			</div>
		</div>
		<!-- /.row -->
	</div><!-- /.container-fluid -->
</div>
<script>
//判断是否敲击了Enter键 
	$(document).keyup(function(event){ 
		if(event.keyCode ==13){ 
		  $("#login").trigger("click"); 
		} 
	});
	function doLogin(form) {
		//输入验证
		let email = form.email.value;
		let password = form.password.value;
		if (!email || email == "") {
		showmsg("用户名不能为空！");
			return false;
		}else{
			// 判断邮箱格式
			   // /^([a-zA-Z]|[0-9])+$/
				let reg=/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
			   if(!reg.test(email)){
				   showmsg("请输入邮箱！");
				   return false;
			   }
		   }
		if (!password || password == "") {
			showmsg("密码不能为空");
			return false;
		} 
		else {
			$.ajax({
				type: "POST", //提交的方法
				url: "doLogin", //提交的地址
				data: $('#loginForm').serialize(), // 序列化表单值
				dataType:'json',
				async: false,
				error: function(request) {
					//失败提示
					showmsg("连接服务器失败!");
				},
				success: function(data) { //成功
					showmsg("正在登录中");
					console.log(data);
					if (data.status===0) loadSubPage('user');
					else showmsg("用户不存在或密码不匹配!");
				}
			});
			return false;
		}
	}

	function showmsg(msg) {
		$("#checkmsg").text(msg);
	}
</script>
